package com.itany.corejava.day08;

import java.util.Objects;

public class Person implements Cloneable {

    private String id;
    private String name;
    private int age;
    private boolean sex;
    private Address address;



    public Person() {
    }

    public Person(String id, String name, int age, boolean sex) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
    //
    // @Override
    // public boolean equals(Object obj) {
    //     if(obj==null){
    //         return false;
    //     }
    //     if(this==obj){
    //         return true;
    //     }
    //     if(obj instanceof Person){
    //         Person p= (Person) obj;
    //
    //         return p.id.equals(this.id);
    //     }
    //     return false;
    //
    // }
    //
    // @Override
    // public int hashCode() {
    //     return 1;
    // }


    @Override
    protected void finalize() throws Throwable {
        System.out.println("释放内存");
        super.finalize();
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }
}
